package com.wh.wisdomsite.xbox.client.service.al;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wh.wisdomsite.xbox.al.entity.AlarmSign;
import com.wh.wisdomsite.xbox.al.service.IAlarmSignService;
import com.wh.wisdomsite.xbox.common.Constants;
import com.wh.wisdomsite.xbox.common.annotation.NeedInSessionType;
import com.wh.wisdomsite.xbox.common.annotation.ServiceMethod;
import com.wh.wisdomsite.xbox.common.annotation.ServiceProvider;
import com.wh.wisdomsite.xbox.common.reponse.CommonResult;
import com.wh.wisdomsite.xbox.pojo.al.GetAlarmIn;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 客户端警报controller
 *
 * @version V1.0
 * @Package: com.wh.wisdomsite.xbox.client.service.ba
 * @author: 丁奕
 * @date: 2018-09-25 15:40
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 **/
@ServiceProvider()
public class AlarmSignClientService {

    private static final Log logger = LogFactory.getLog(AlarmSignClientService.class);

    @Autowired
    private IAlarmSignService iAlarmSignService;

    /**
     * 通过项目ID，时间，警报类型，警报类别，警报细分获取警报集合
     * @param in
     */
    @ServiceMethod(method = "wh.zhgd.al.alarmSign.getList", title = "获取警报列表", version = "1.0", needInSession = NeedInSessionType.NO)
    public CommonResult getList(GetAlarmIn in){
        logger.info("获取警报列表->>wh.zhgd.al.alarmSign.getList->>开始");
        CommonResult commonResult = new CommonResult();
        List<AlarmSign> alarmSignList = new ArrayList<AlarmSign>();
        try{
            EntityWrapper<AlarmSign> ew = new EntityWrapper<>();
            ew.setEntity(new AlarmSign());
            if(StringUtils.isNotEmpty(in.getPrId())){
                ew.eq("prId", in.getPrId());
            }
            if(StringUtils.isNotEmpty(in.getStartTime())){
                ew.ge("alarmTime", in.getStartTime());
            }
            if(StringUtils.isNotEmpty(in.getEndTime())){
                ew.lt("alarmTime", in.getEndTime());
            }
            if(StringUtils.isNotEmpty(in.getAlarmType())){
                ew.eq("alarmType", in.getAlarmType());
            }
            if(StringUtils.isNotEmpty(in.getAlarmCategory())){
                ew.eq("alarmCategory", in.getAlarmCategory());
            }
            if(StringUtils.isNotEmpty(in.getAlarmSubdivided())){
                ew.eq("alarmSubdivided", in.getAlarmSubdivided());
            }
            alarmSignList = iAlarmSignService.selectList(ew);
            commonResult.setCode(Constants.CODE_SUCCESS);
            commonResult.setMessage(Constants.CODE_SUCCESS_MSG);
            commonResult.setResult(alarmSignList);
            logger.info("获取警报列表->>wh.zhgd.al.alarmSign.getList->>结束");
        }catch (Exception e){
            logger.error("获取警报列表->>wh.zhgd.al.alarmSign.getList->>异常：" + e.getMessage());
            commonResult.setCode(Constants.CODE_FAIL);
            commonResult.setMessage(Constants.CODE_FAIL_MSG);
            in.getXboxRequestContext().setException(new Exception(e.getMessage()));
            e.printStackTrace();
        }
        return commonResult;
    }
}
